%% plot hovmoller 
casename='OBL80_S0_s1200e1850_slow';
nyr=110; time=(1:12*nyr)-1;
ts=1200+time.*(5./12); 
varname='Insolation';
varunit='W/m^2';

% casename='OBL0_S0_s1365e1850_slow';
% nyr=77; time=(1:12*nyr)-1;
% ts=1360+time.*(5./12);
% varname='Insolation';
% varunit='W/m^2';

% casename='OBL80_Om_s5e02_1550_combine';
% nyr=80; time=(1:12*nyr)-1;
% ts=5.*0.04.^(time./12./nyr); 
% varname='Rotation rate';
% varunit='/earth day';

fname=['vinth3_All_monthly_lonavg_',casename,'.nc'];
lat=ncread(fname,'lat'); nlat=length(lat);
lev=ncread(fname,'lev'); nlev=length(lev);
 

%% CLDTOT
CLDTOT=ncread(fname,'CLDTOT',[1,1],[Inf,nyr*12]);
figure
colormap(hot)
subplot(2,2,[1,3])
contourf(lat,ts,CLDTOT',[0:0.05:1],'LineColor','none')
caxis([0 1])
xlabel('lat'); xticks([-90:30:90])
ylabel([varname,' (',varunit,')'])
set(gca,'FontSize',20)

if strcmp(varname,'Rotation rate')
    set(gca,'yscale','log','ydir','reverse')
    yticks([0.2,0.5,1,2,5])
    ylim([0.2 5])
end

subplot(2,2,4,'Position',[0.555 0.11 0.3347 0.36])
iyr=1;
indmon=[1:12]+(iyr-1)*12;
contourf(lat,indmon,CLDTOT(:,indmon)',[0:0.05:1],'LineColor','none')
caxis([0 1])
yticks([[indmon(1):3:indmon(end)]])
yticklabels({'Jan','Apr','Jul','Oct'})
xticks([-90:30:90])
set(gca,'FontSize',20)
title([varname,'=',sprintf('%3.1f',ts(indmon(1))),' ',varunit],'FontSize',17)
xlabel('lat')

subplot(2,2,2,'Position',[0.555 0.53 0.3347 0.36])
iyr=nyr;
indmon=[1:12]+(iyr-1)*12;
contourf(lat,indmon,CLDTOT(:,indmon)',[0:0.05:1],'LineColor','none')
caxis([0 1])
yticks([[indmon(1):3:indmon(end)]])
yticklabels({'Jan','Apr','Jul','Oct'})
xticks([])
set(gca,'FontSize',20)
title([varname,'=',sprintf('%3.1f',ts(indmon(1))),' ',varunit],'FontSize',17)

colorbar('Position', [0.91 0.2 0.02 0.6])
set(gcf,'Position',[560   444   659   504])

saveas(gcf,['hov_cloud_',casename,'.png'],'png')

%% U wind
levshow=10;
%contours=[-200,-150,-100,-80:10:-20,-20:5:20,20:10:80,100,150,200];
contours=[-200:20:200];
[~,il]=min(abs(lev-levshow));
U2D=squeeze(ncread(fname,'U',[1,il,1],[Inf,1,nyr*12]));
figure
polarmap(jet(length(contours+1)),0.6)
subplot(2,2,[1,3])
contourf(lat,ts,U2D',[-1000,contours,1000],'LineColor','none')
caxis([contours(1) contours(end)])
hold on
contour(lat(2:end-1),ts,U2D(2:end-1,:)',[0,0],'k','LineWidth',0.2)
xlabel('lat'); xticks([-90:30:90])
ylabel([varname,' (',varunit,')'])
set(gca,'FontSize',20)

if strcmp(varname,'Rotation rate')
    set(gca,'yscale','log','ydir','reverse')
    yticks([0.2,0.5,1,2,5])
    ylim([0.2 5])
end

subplot(2,2,4,'Position',[0.555 0.11 0.3347 0.36])
iyr=1;
indmon=[1:12]+(iyr-1)*12;
contourf(lat,indmon,U2D(:,indmon)',[-1000,contours,1000],'LineColor','none')
caxis([contours(1) contours(end)])
hold on
contour(lat(2:end-1),indmon,U2D(2:end-1,indmon)',[0,0],'k','LineWidth',2)
yticks([[indmon(1):3:indmon(end)]])
yticklabels({'Jan','Apr','Jul','Oct'})
xticks([-90:30:90])
set(gca,'FontSize',20)
title([varname,'=',sprintf('%3.1f',ts(indmon(1))),' ',varunit],'FontSize',17)
xlabel('lat')

subplot(2,2,2,'Position',[0.555 0.53 0.3347 0.36])
iyr=nyr;
indmon=[1:12]+(iyr-1)*12;
contourf(lat,indmon,U2D(:,indmon)',[-1000,contours,1000],'LineColor','none')
caxis([contours(1) contours(end)])
hold on
contour(lat(2:end-1),indmon,U2D(2:end-1,indmon)',[0,0],'k','LineWidth',2)
yticks([[indmon(1):3:indmon(end)]])
yticklabels({'Jan','Apr','Jul','Oct'})
xticks([])
set(gca,'FontSize',20)
title([varname,'=',sprintf('%3.1f',ts(indmon(1))),' ',varunit],'FontSize',17)

colorbar('Position', [0.91 0.2 0.02 0.6])
set(gcf,'Position',[560   444   659   504])

saveas(gcf,['hov_U',num2str(levshow),casename,'.png'],'png')